This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
function RunWithParams($methodName, $params)
{
$response = array(
"template" => "text_to_speech.tpl",
"override" => $params["override"],
);
if($methodName == "speak") {
$text = $params["text_to_speak"];
if($text) {
// Massage the text so AppleScript doesn't barf on it
$text = str_replace("\\'", "'\"'\"'", $text);
//echo "Text to speak: $text<br />";
// Create a temp file to store the AIFF sound data
$tmpname = tempnam("/tmp", "speakAIFF");
$aiffname = $tmpname . ".aiff";
rename($tmpname, $aiffname);
//
//echo "Temp AIFF File: $aiffname<br />";
// Save the sound file as an AIFF Sound
$result = exec("osascript -e 'say \"$text\" saving to (POSIX file \"$aiffname\") with waiting until completion' -e 'return 1'");
if($result == 1) {
//echo "Result of creating AIFF File: $result<br />";
$tmpname = tempnam("/tmp", "speakWAV");
$wavname = $tmpname . ".wav";
rename($tmpname, $wavname);
// Export the sound file to WAV Format
//$result = exec("osascript -e 'beep'");
$result = exec("osascript -e 'tell application \"QuickTime Player\" to set theFile to open alias (POSIX file \"$aiffname\" as text)' -e 'tell application \"QuickTime Player\" to export theFile to (POSIX file \"$wavname\") as wave with replacing' -e 'tell application \"QuickTime Player\" to close theFile' -e 'return 1'");
//echo "Result of exporting to WAV: $result<br />";
if($result == 1) {
// first delete the temp AIFF file
@unlink($aiffname);
// now, send the WAV file to the client device
$filename = basename($wavname);
header("Cache-Control: no-cache, must revalidate");